/**
 * 集合
 * author:dengyiping
 * date:2016/08/01
 */

/*set 通过数组创建Set对象，set可以用于数组去重*/
var mySet = new Set();
[2, 3, 4, 1, 3, 2, 3].map(value => mySet.add(value));
console.log("mySet size="+mySet.size);//print:mySet size=4
for(let i of mySet){
    console.log(i);
}

console.log();
var items = new Set([1, 2, 3, 4, 5, 5, 5, "5"]);// set中不会发生数据类型,5==="5" false
console.log("items size=" + items.size); //print:items size=6
for(let i of items){
    console.log(i);
}

/*两个对象总是不想等的 */
console.log();
let set = new Set();
set.add({});
console.log(set.size);//print:1

set.add({});
console.log(set.size);//print:2

/*map */
var mp = new Map();
var obj = {desc:"this is an Object"};

mp.set(obj, "the key is an object");
mp.get(obj);
mp.has(obj);
console.log("map~size="+ mp.size + ","+mp.get(obj));//print:the key is an object
// mp.delete(obj);
// mp.has(obj);

let map = new Map();

map
.set(1, 'aaa')
.set(1, 'bbb');
// map.clear() 
console.log(map.get(1)); // "bbb"

//遍历
map.set(2, 'b')
map.set(3, 'c');
//Get all the keys ,others: map.values()
for (let k of map.keys() ){
    console.log(k);
}

for (let option of map.entries()){
    console.log(option instanceof Array ? "array":"others"); //print :array
    console.log(option[0], option[1]);
}